﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace FlexnetConsultants.CookieNotification.Code
{
    public class Logger
    {
        internal Logger()
        {
            _category = new SPDiagnosticsCategory("CookieNotification", TraceSeverity.Verbose, EventSeverity.Verbose);
        }

        private static object _synclock= new object();

        SPDiagnosticsCategory _category = null;

        private static Logger _Current = null;
        public static Logger Current
        {
            get
            {

                lock (_synclock)
                {
                    if (_Current == null)
                    {
                        _Current = new Logger();
                    }
                }
                return _Current;
            }
        }

        public void LogMessage(string Message)
        {

            SPDiagnosticsService.Local.WriteTrace(1, _category, TraceSeverity.Medium, Message, null);
        }

        public void LogException(string Message, Exception ex)
        {

            SPDiagnosticsService.Local.WriteTrace(1, _category, TraceSeverity.High, "{0} {1}", new object[] {Message, ex.Message});
        }

    }
}
